import { Effect, ImmerReducer } from '@/.umi/plugin-dva/connect'
import { getProList, getRecommendOrSeckillListReq } from '../../service/prolist'
import { IPro } from './pro'
export interface IProList{
    proList: Array<IPro>
    recommendList: Array<IPro>
    seckillList: Array<IPro>
}
export interface IProModel{
    namespace: 'pro'
    state: IProList
    effects: {
        getProListEffect: Effect
        getRecommendEffect: Effect
        getSeckillEffect: Effect
    }
    reducers: {
        UPDATE_PRO_LIST: ImmerReducer
        UPDATE_COMMEND: ImmerReducer
        UPDATE_SECKILL: ImmerReducer
    }
}
const proModel:IProModel = {
    namespace: 'pro',
    state: {
        proList: [],
        recommendList: [],
        seckillList: []
    },
    effects: {
        *getProListEffect({payload},{call,put}){
            const res = yield call(getProList,payload)
            yield put({
                type:'UPDATE_PRO_LIST',
                payload: res.data
            })
        },
        *getRecommendEffect({payload},{call,put}){
            const res = yield call(getRecommendOrSeckillListReq,payload)
            yield put({
                type: 'UPDATE_COMMEND',
                payload:res.data
            })
        },
        *getSeckillEffect({payload},{call,put}){
            const res = yield call(getRecommendOrSeckillListReq,payload)
            yield put({
                type: 'UPDATE_SECKILL',
                payload:res.data
            })
        }
    },
    reducers:{
        UPDATE_PRO_LIST(state,action){
            // console.log(action,789);
            state.proList = action.payload
        },
        UPDATE_COMMEND(state,action){
            // console.log(action,789);
            state.recommendList = action.payload
        },
        UPDATE_SECKILL(state,action){
            // console.log(action,789);
            state.seckillList = action.payload
        }
    }
}
export default proModel